home *** CD-ROM | disk | FTP | other *** search
- Path: god.bel.alcatel.be!btmpj7!ian
- From: ian@rsd.bel.alcatel.be (Ian Ward)
- Newsgroups: comp.lang.c
- Subject: Re: Tough FACTORIAL math problem...
- Date: 15 Feb 1996 09:11:42 GMT
- Organization: Alcatel Bell Telephone
- Distribution: world
- Message-ID: <4futce$r3b@btmpjg.god.bel.alcatel.be>
- References: <4fr8be$ass@news.iconn.net>
- Reply-To: ian@rsd.bel.alcatel.be
- NNTP-Posting-Host: btmpj7.rsd.bel.alcatel.be
-
-
- Working out the last non zero digit of a factorial is much easier
- than working out the factorial.
- This algorithm might not be exactly right but its thereabouts
- Note : it's just typed in and it's not in 'C' either.
-
-
- function last_digit (num : in positive) return positive is
- sings : array (0 .. 9) of integer :=
- (1, 1, 2, 6, 4, 2, 2, 4, 2, 8);
- tens : array (0 .. 3) of integer := (8, 4, 2, 6);
- ret_val : integer := sings (num rem 10);
- begin
- if num > 9
- then
- ret_val := ret_val * tens ((num/10-1) rem 4);
- end if;
- return ret_val;
- end;
-
- ---
- Ian Ward's opinions only : ian@rsd.bel.alcatel.be
-
-